package controllers

import (
	"errmsg"
	"github.com/astaxie/beego/logs"
	"smart_home/api/models"
)

type MessageController struct {
	BaseController
}

// @Title 消息列表
// @param page int true
// @param row int true
// @router / [get]
func (c *MessageController) GetAll() {
	var (
		page int
		err error
		lists []*models.Messages
	)

	if page, err = c.GetInt("page", 1); err != nil {
		logs.Error("GetAll:", errmsg.ErrResponseParameter)
		c.Error(errmsg.ErrResponseParameter)
		return
	}

	if lists, err = models.GetAllMessageByUid(c.User.Id, page); err != nil {
		logs.Error("GetAll:", err)
		c.Error(errmsg.ErrResponseSystem)
		return
	}

	c.Success(lists)
}

// @Title 清除消息
// @router / [delete]
func (c *MessageController) Delete() {
	if !models.ClearMessagesByUid(c.User.Id) {
		c.Error(errmsg.ErrResponseFail)
		return
	}
	c.Success(nil)
}